package com.msmall.community.admin.service.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.msmall.community.ApplicationManager;
import com.msmall.community.admin.service.MemoryManager;
import com.msmall.community.common.CommunityInitialize;
import com.msmall.community.common.service.CommendManager;
import com.msmall.community.keyword.service.KeywordManager;
import com.msmall.community.klg.service.KlgManager;

public class MemoryManagerImpl implements MemoryManager{

	private static final Log logger = LogFactory.getLog(MemoryManagerImpl.class);
	
	public void refresh(int type) throws Exception {
		logger.debug("refresh : " + type);
		switch(type){
			case MemoryManager.MEMORY_USERAGENT_KEY:
				CommunityInitialize.refreshUserAgent();
				break;
			case MemoryManager.MEMORY_BBS_ALL_KEY:
				CommunityInitialize.refreshBoard();
				break;
			case MemoryManager.MEMORY_BBS_BOARD_KEY:
				CommunityInitialize.refreshBoard();
				break;
			case MemoryManager.MEMORY_SYSTEM_CONFIG_KEY:
				CommunityInitialize.refreshConfig();
				break;
			case MemoryManager.MEMORY_SCORERULE_KEY:
				CommunityInitialize.refreshScoreRule();
				break;
			case MemoryManager.MEMORY_RANKRULE_KEY:
				CommunityInitialize.refreshRankRule();
				break;
			case MemoryManager.MEMORY_PLAY_KEY:
				CommunityInitialize.refreshPlay();
				break;
			case MemoryManager.MEMORY_COMMEND_BBS_KEY:
				{
					CommendManager commendManager = (CommendManager) ApplicationManager.appContext.getBean("commendManager");
					commendManager.refreshBBS();
					break;
				}
			case MemoryManager.MEMORY_LINK_KEY:
				CommunityInitialize.refreshLink();
				break;
			case MemoryManager.MEMORY_DEPARTMENT_KEY:
				CommunityInitialize.refreshDepartment();
				break;
			case MemoryManager.MEMORY_SEGMENT_KEY:
				CommunityInitialize.refreshSegment();
				break;
			case MemoryManager.MEMORY_COMMEND_QUESTION_KEY:
			{
				CommendManager commendManager = (CommendManager) ApplicationManager.appContext.getBean("commendManager");
				commendManager.refreshQuestion();
				break;
			}
			case MemoryManager.MEMORY_COMMEND_KLG_KEY:
			{
				CommendManager commendManager = (CommendManager) ApplicationManager.appContext.getBean("commendManager");
				commendManager.refreshKlg();
				break;
			}
			case MemoryManager.MEMORY_KLG_HOT_KEY:
			{
				KlgManager manager = (KlgManager) ApplicationManager.appContext.getBean("klgManager");
				manager.refreshKlgByClickAmount(30);//KlgJob
				break;
			}
			case MemoryManager.MEMORY_KEYWORD_KEY:
			{
				KeywordManager manager = (KeywordManager) ApplicationManager.appContext.getBean("keywordManager");
				manager.refresh();
				break;
			}
			case MemoryManager.MEMORY_SITE_INDEX_KEY:
			{
				CommendManager commendManager = (CommendManager) ApplicationManager.appContext.getBean("commendManager");
				commendManager.refreshSiteIndex();
				break;
			}
		}
	}

}
